package com.zp.kidshop.common.pojo;

import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

/**
 * @Title: SysProp.java  
 * @Package com.minghang.common.pojo
 * @Description:<p> 静态类
 * @author 张鹏  
 * @date 2017年1月6日 上午10:23:52
 * @version V1.0
 */
public class SysProp { 
	/** 当前环境判断 true为测试环境，false为正式环境 （当前默认为测试环境） */
	public static boolean isDebug = true;
	
	private static final SimpleDateFormat SDF_24H = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
//	private static final SimpleDateFormat TIME_24H = new SimpleDateFormat("HH:mm:ss");
	
	public static final String startTime = "2";
	
	public static final String endTime = "6";
	
	//自定义密钥
	public static final String SQLKEY = "okdaijkl^swf@#$LKJds567q9KLJ^*1lkjsad";
	
	/**数字格式化为字符串,保留后两位*/
	public static final DecimalFormat DECIMALFORMAT = new DecimalFormat("#0.00");
	/**数字格式化为字符串,保留后一位*/
	public static final DecimalFormat DECIMALFORMAT_N = new DecimalFormat("#0.0");
	/**数字格式化为字符串,保留小数点后2位非0位*/
	public static final DecimalFormat DECIMALFORMAT_NZ = new DecimalFormat("#0.##");
	/**数字类型取整*/
	public static final DecimalFormat DECIMALFORMAT_NZ1 = new DecimalFormat("###");
	
	/**post请求格式*/
	public static String APPLICATION_JSON= "application/json";			//json
	
	/**加密解密key*/
//	public static final String KEY = "SECRET_A_Mpd42L9";
	public static final String KEY = "okdaixeenho2xhzt";
	
	/**调用中金的URL*/
	private static String SEND_ZHONGJIN_URL;
	
	/**发送短信接口内网地址*/
	private static String smsIntranet;

	/**发送短信接口外网地址*/
	private static String smsInternet;

	/**发送短信需要的Key*/
	private static String smsKey;

	/**发送短信账户*/
	private static String smsAccount;

	/**发送短信密码*/
	private static String smsPwd;

	/**短信验证码倒计时单位=秒*/
	private static int tick;
	
	/**JS,CSS版本号*/
	private static String version;
	

	/**老项目的URL路径，自己的项目自己修改*/
	public static String OldWebUrl;
	
	/**阿里IP归属*/
	public static String URI_IPINFO = "http://ip.taobao.com/service/getIpInfo.php?ip=";
	
	/** 读取property ，并且设置相关的属性值，已经环境标识符 */
	static {
		Properties prop = new Properties();
	    String fileUrl = "/web/sys.properties";
	    String config = System.getProperty("RUN_ENV");
	    try(
	    	InputStream in = SysProp.class.getResourceAsStream(fileUrl);){
	        prop.load(in);
	        if("production".equals(config)){
	        	isDebug = false;
	        }
	     	// 调用中金的URL
        	SEND_ZHONGJIN_URL  = prop.getProperty("zhongjin.url");
        	
        	smsIntranet = prop.getProperty("WEB.SMS.INTRANET");
            smsInternet = prop.getProperty("WEB.SMS.INTERNET");
            smsKey      = prop.getProperty("WEB.SMS.KEY");
            smsAccount  = prop.getProperty("WEB.SMS.ACCOUNT");
            smsPwd      = prop.getProperty("WEB.SMS.PWD");
            tick        = Integer.parseInt(prop.getProperty("WEB.SMS.TICK"));
            version     = prop.getProperty("WEB.version");
            OldWebUrl   = prop.getProperty("WEB.oldweburl");
	        //.....需要的自己添加
        	
        	prop.clear();
	        
	    } catch (IOException e) {
	        e.printStackTrace();
	    }finally{
	        prop = null;
	    }
	}
	

	/**-------------------------------get方法-----------------------------------*/
	/**获取当前时间-24小时制*/
	public static String getThisTime(){
		return SDF_24H.format(new Date());
	}
	/**获取调用中金的URL*/
	public static String getZHONGJIN_URL() {
		return SEND_ZHONGJIN_URL;
	}
	/**true测试环境,false生产环境*/
	public static boolean isDebug(){
		return isDebug;
	}
	/**
	 * DEBUG下使用内网地址,否则使用外网
	 **/
	public static String getSmsAddr(){
		if (isDebug) {
			return smsIntranet;
		}else {
			return smsInternet;
		}
	}

	/**发送短信需要的Key*/
	public static String getSmsKey(){
		return smsKey;
	}

	/**发送短信需要的账户*/
	public static String getSmsAccount(){
		return smsAccount;
	}
	
	/**发送短信密码*/
	public static String getSmsPwd(){
		return smsPwd;
	}

	/**短信验证码倒计时单位=秒*/
	public static int getTimeTick(){
		return tick;
	}
	
	/**获取JS,CSS版本号*/
	public static String getVersion() {
		return version;
	}
	
	/**老项目的URL路径，自己的项目自己修改*/
	public static String getOldWebUrl() {
		return OldWebUrl;
	}


	/**-------------------------------错误提示代码-----------------------------------*/
	/**无权访问方法*/
	public static final String ERR_NO_SECURITYC = "JEC01";
	public static final String ERR_NO_SECURITYM = "无权的方法访问!";

	/**非法方法调用*/
	public static final String ERR_ILLEGAL_ACCESSC = "JEC02";
	public static final String ERR_ILLEGAL_ACCESSM = "非法方法调用!";
	
	/**调用参数类型异常*/
	public static final String ERR_ILLEGAL_ARGUMENTC = "JEC03";
	public static final String ERR_ILLEGAL_ARGUMENTM = "调用参数类型异常!";
	
	/**调用方法内部异常*/
	public static final String ERR_INVOCATION_TARGETC = "JEC04";
	public static final String ERR_INVOCATION_TARGETM = "调用方法内部异常!";
	
	/**调用存储过程异常*/
	public static final String ERR_ACCESS_DBC = "JEC05";
	public static final String ERR_ACCESS_DBM = "数据获取异常!";
	
	
}







